package br.com.jk.fornecedor;

import br.com.jk.cidade.Cidade;
import br.com.jk.cidade.CidadeJDialog;
import br.com.jk.cidade.CidadeRn;
import br.com.jk.email.EmailTableModel;
import br.com.jk.master.Master;
import br.com.jk.telefone.TelefoneTableModel;
import br.com.jk.util.Util;
import java.awt.event.KeyEvent;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author camilo
 */
public class FornecedorJDialog extends javax.swing.JDialog {

  private static FornecedorJDialog fjdialog;
  // Model da tabela
  FornecedorTableModel fornTm = new FornecedorTableModel();
  TelefoneTableModel telTm = new TelefoneTableModel();
  EmailTableModel emTm = new EmailTableModel();
  FornecedorController fControl = new FornecedorController(this);
  List<Fornecedor> lstForn;
  private int idEnd;
//  atributos utilizados nas pesquisas externas
  private JTextField idPesquisa;
  private JTextField razaoPesquisa;
  private boolean modoConsultaExt;

  public static FornecedorJDialog getInstance(java.awt.Frame parent, boolean modal) {
    if (fjdialog == null) {
      fjdialog = new FornecedorJDialog(parent, modal);
    }
    return fjdialog;
  }

  public static FornecedorJDialog getInstance(java.awt.Frame parent, boolean modal, JTextField id, JTextField razao) {
    if (fjdialog == null) {
      fjdialog = new FornecedorJDialog(parent, modal, id, razao);
    }
    return fjdialog;
  }

  /**
   * Creates new form FornecedorJDialog
   */
  private FornecedorJDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    setLocationRelativeTo(null);
    fControl.listar();
    jlFiltro.setVisible(false);
  }

  private FornecedorJDialog(java.awt.Frame parent, boolean modal, JTextField id, JTextField razao) {
    super(parent, modal);

    this.idPesquisa = id;
    this.razaoPesquisa = razao;
    this.modoConsultaExt=true;

    initComponents();
    setLocationRelativeTo(null);
    fControl.listar();
    jlFiltro.setVisible(false);
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do
   * NOT modify this code. The content of this method is always regenerated by the Form
   * Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    JtbMaster = new javax.swing.JToolBar();
    JbNovo = new javax.swing.JButton();
    JbSalvar = new javax.swing.JButton();
    JbEditar = new javax.swing.JButton();
    JbCancelar = new javax.swing.JButton();
    JbExcluir = new javax.swing.JButton();
    JbBuscar = new javax.swing.JButton();
    JbRelatorio = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    JbRefresh = new javax.swing.JButton();
    jlFiltro = new javax.swing.JLabel();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    jScrollPane1 = new javax.swing.JScrollPane();
    jtFornecedor = new javax.swing.JTable();
    jpDados = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    jtfId = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jtfFantasia = new javax.swing.JTextField();
    jLabel3 = new javax.swing.JLabel();
    jtfRazao = new javax.swing.JTextField();
    jLabel4 = new javax.swing.JLabel();
    jtfCnpj = new javax.swing.JTextField();
    jLabel5 = new javax.swing.JLabel();
    jtfIe = new javax.swing.JTextField();
    jLabel7 = new javax.swing.JLabel();
    jtfRua = new javax.swing.JTextField();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jtfComplemento = new javax.swing.JTextField();
    jtfNumero = new javax.swing.JTextField();
    jLabel10 = new javax.swing.JLabel();
    jtfBairro = new javax.swing.JTextField();
    jLabel11 = new javax.swing.JLabel();
    jtfIdCidade = new javax.swing.JTextField();
    jtfCidade = new javax.swing.JTextField();
    jLabel12 = new javax.swing.JLabel();
    jtfCep = new javax.swing.JTextField();
    jScrollPane2 = new javax.swing.JScrollPane();
    jtaObs = new javax.swing.JTextArea();
    jLabel15 = new javax.swing.JLabel();
    jcbPFisica = new javax.swing.JCheckBox();
    jbAddTelefone = new javax.swing.JButton();
    jbEditTelefone = new javax.swing.JButton();
    jbAddEmail = new javax.swing.JButton();
    jbEditEmail = new javax.swing.JButton();
    jScrollPane6 = new javax.swing.JScrollPane();
    jtTelefone = new javax.swing.JTable();
    jScrollPane7 = new javax.swing.JScrollPane();
    jtEmail = new javax.swing.JTable();
    jbRemoveTelefone = new javax.swing.JButton();
    jbRemoveEmail = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Cadastro de fornecedores");

    JtbMaster.setRollover(true);

    JbNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-new.png"))); // NOI18N
    JbNovo.setToolTipText("Novo Registro");
    JbNovo.setFocusable(false);
    JbNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbNovo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbNovoActionPerformed(evt);
      }
    });
    JtbMaster.add(JbNovo);

    JbSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-save-hd.png"))); // NOI18N
    JbSalvar.setToolTipText("Salvar Registro");
    JbSalvar.setEnabled(false);
    JbSalvar.setFocusable(false);
    JbSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbSalvar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbSalvarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbSalvar);

    JbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-edit.png"))); // NOI18N
    JbEditar.setToolTipText("Alterar registro");
    JbEditar.setEnabled(false);
    JbEditar.setFocusable(false);
    JbEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbEditar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbEditarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbEditar);

    JbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/dialog-cancel.png"))); // NOI18N
    JbCancelar.setToolTipText("Cancelar");
    JbCancelar.setEnabled(false);
    JbCancelar.setFocusable(false);
    JbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbCancelarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbCancelar);

    JbExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/archive-remove.png"))); // NOI18N
    JbExcluir.setToolTipText("Excluir");
    JbExcluir.setEnabled(false);
    JbExcluir.setFocusable(false);
    JbExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbExcluir.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbExcluirActionPerformed(evt);
      }
    });
    JtbMaster.add(JbExcluir);

    JbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/edit-find.png"))); // NOI18N
    JbBuscar.setToolTipText("Buscar");
    JbBuscar.setEnabled(false);
    JbBuscar.setFocusable(false);
    JbBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbBuscar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbBuscarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbBuscar);

    JbRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/report.png"))); // NOI18N
    JbRelatorio.setToolTipText("Relatórios");
    JbRelatorio.setEnabled(false);
    JbRelatorio.setFocusable(false);
    JbRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbRelatorio.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbRelatorioActionPerformed(evt);
      }
    });
    JtbMaster.add(JbRelatorio);
    JtbMaster.add(jSeparator1);

    JbRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/view-refresh.png"))); // NOI18N
    JbRefresh.setToolTipText("Atualizar registros da lista");
    JbRefresh.setFocusable(false);
    JbRefresh.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbRefresh.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbRefresh.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbRefreshActionPerformed(evt);
      }
    });
    JtbMaster.add(JbRefresh);

    jlFiltro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/task-attempt.png"))); // NOI18N
    JtbMaster.add(jlFiltro);
    JtbMaster.add(jSeparator2);

    jtFornecedor.setModel(fornTm);
    jtFornecedor.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent evt){
        if (evt.getValueIsAdjusting()){
          return;
        }
        int selected = jtFornecedor.getSelectedRow();
        fControl.selecionado();
      }
    });

    jtFornecedor.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent evt){
        if (evt.getValueIsAdjusting()){
          return;
        }
        int selected = jtFornecedor.getSelectedColumn();
        fControl.selecionado();
      }
    });
    jtFornecedor.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_ID).setPreferredWidth(60);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_BAIRRO).setPreferredWidth(100);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_CEP).setPreferredWidth(80);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_CIDADE).setPreferredWidth(100);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_CNPJ).setPreferredWidth(130);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_COMPLEMENTO).setPreferredWidth(100);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_FANTASIA).setPreferredWidth(150);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_IE).setPreferredWidth(100);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_NUMERO).setPreferredWidth(60);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_OBSERVACAO).setPreferredWidth(200);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_RAZAO).setPreferredWidth(300);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_RUA).setPreferredWidth(300);
    jtFornecedor.getColumnModel().getColumn(FornecedorTableModel.COLUNA_COD_PFISICA).setPreferredWidth(50);
    jtFornecedor.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        jtFornecedorMouseClicked(evt);
      }
    });
    jtFornecedor.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtFornecedorKeyPressed(evt);
      }
    });
    jScrollPane1.setViewportView(jtFornecedor);

    jpDados.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados"));

    jLabel2.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel2.setText("Id");

    jtfId.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfId.setEnabled(false);
    jtfId.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfIdKeyPressed(evt);
      }
    });

    jLabel1.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel1.setText("Nome Fantasia");

    jtfFantasia.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfFantasia.setEnabled(false);
    jtfFantasia.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfFantasiaKeyPressed(evt);
      }
      public void keyReleased(java.awt.event.KeyEvent evt) {
        jtfFantasiaKeyReleased(evt);
      }
    });

    jLabel3.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel3.setText("Razão Social");

    jtfRazao.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfRazao.setEnabled(false);
    jtfRazao.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfRazaoKeyPressed(evt);
      }
      public void keyReleased(java.awt.event.KeyEvent evt) {
        jtfRazaoKeyReleased(evt);
      }
    });

    jLabel4.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel4.setText("CNPJ/CPF");

    jtfCnpj.setDocument(djtfCnpj);
    jtfCnpj.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfCnpj.setEnabled(false);
    jtfCnpj.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfCnpjKeyPressed(evt);
      }
    });

    jLabel5.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel5.setText("IE/RG");

    jtfIe.setDocument(djtfIe);
    jtfIe.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfIe.setEnabled(false);
    jtfIe.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfIeKeyPressed(evt);
      }
    });

    jLabel7.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel7.setText("Endereço");

    jtfRua.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfRua.setEnabled(false);
    jtfRua.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfRuaKeyPressed(evt);
      }
      public void keyReleased(java.awt.event.KeyEvent evt) {
        jtfRuaKeyReleased(evt);
      }
    });

    jLabel8.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel8.setText("Complemento");

    jLabel9.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel9.setText("Nº");

    jtfComplemento.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfComplemento.setEnabled(false);
    jtfComplemento.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfComplementoKeyPressed(evt);
      }
    });

    jtfNumero.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfNumero.setEnabled(false);
    jtfNumero.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfNumeroKeyPressed(evt);
      }
    });

    jLabel10.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel10.setText("Bairro");

    jtfBairro.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfBairro.setEnabled(false);
    jtfBairro.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfBairroKeyPressed(evt);
      }
      public void keyReleased(java.awt.event.KeyEvent evt) {
        jtfBairroKeyReleased(evt);
      }
    });

    jLabel11.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel11.setText("Cidade");

    jtfIdCidade.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfIdCidade.setEnabled(false);
    jtfIdCidade.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfIdCidadeKeyPressed(evt);
      }
    });

    jtfCidade.setEditable(false);
    jtfCidade.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfCidade.setEnabled(false);
    jtfCidade.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfCidadeKeyPressed(evt);
      }
    });

    jLabel12.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel12.setText("CEP");

    jtfCep.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfCep.setEnabled(false);
    jtfCep.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfCepKeyPressed(evt);
      }
    });

    jtaObs.setColumns(20);
    jtaObs.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtaObs.setRows(5);
    jtaObs.setEnabled(false);
    jScrollPane2.setViewportView(jtaObs);

    jLabel15.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel15.setText("Observações");

    jcbPFisica.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jcbPFisica.setText("Pessoa Física");
    jcbPFisica.setToolTipText("Marque essa opção caso o fornecedor seja Pessoa Física");
    jcbPFisica.setEnabled(false);
    jcbPFisica.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jcbPFisicaKeyPressed(evt);
      }
    });

    jbAddTelefone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/add.png"))); // NOI18N
    jbAddTelefone.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbAddTelefoneActionPerformed(evt);
      }
    });

    jbEditTelefone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/pencil.png"))); // NOI18N
    jbEditTelefone.setEnabled(false);

    jbAddEmail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/add.png"))); // NOI18N
    jbAddEmail.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbAddEmailActionPerformed(evt);
      }
    });

    jbEditEmail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/pencil.png"))); // NOI18N
    jbEditEmail.setEnabled(false);

    jtTelefone.setFont(new java.awt.Font("Liberation Sans", 0, 11)); // NOI18N
    jtTelefone.setModel(telTm);
    jtTelefone.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jtTelefone.getColumnModel().getColumn(0).setPreferredWidth(63); //DDD
    jtTelefone.getColumnModel().getColumn(1).setPreferredWidth(85); //Nº
    jScrollPane6.setViewportView(jtTelefone);

    jtEmail.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtEmail.setModel(emTm);
    jScrollPane7.setViewportView(jtEmail);

    jbRemoveTelefone.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/task-reject.png"))); // NOI18N
    jbRemoveTelefone.setEnabled(false);

    jbRemoveEmail.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/task-reject.png"))); // NOI18N
    jbRemoveEmail.setEnabled(false);

    javax.swing.GroupLayout jpDadosLayout = new javax.swing.GroupLayout(jpDados);
    jpDados.setLayout(jpDadosLayout);
    jpDadosLayout.setHorizontalGroup(
      jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jpDadosLayout.createSequentialGroup()
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jtfCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jLabel4))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jtfIe, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jLabel5))
            .addGap(4, 4, 4)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addComponent(jLabel7)
                .addGap(0, 0, Short.MAX_VALUE))
              .addComponent(jtfRua)))
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jLabel2))
            .addGap(2, 2, 2)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jtfFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jLabel1))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel3)
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addComponent(jtfRazao, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcbPFisica))))
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jtfComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jLabel9)
                  .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel10)))
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(jbAddTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jbEditTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                  .addComponent(jbRemoveTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 290, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                  .addComponent(jbAddEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jbEditEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jbRemoveEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(jpDadosLayout.createSequentialGroup()
                    .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                      .addComponent(jLabel11)
                      .addComponent(jtfIdCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addComponent(jLabel12)))
                  .addGroup(jpDadosLayout.createSequentialGroup()
                    .addGap(10, 10, 10)
                    .addComponent(jLabel15)))
                .addGap(0, 0, Short.MAX_VALUE))
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDadosLayout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2)))))
        .addContainerGap())
    );
    jpDadosLayout.setVerticalGroup(
      jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jpDadosLayout.createSequentialGroup()
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(jLabel1)
          .addComponent(jLabel3))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jtfFantasia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jtfRazao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jcbPFisica))
        .addGap(4, 4, 4)
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jLabel5)
              .addComponent(jLabel7)
              .addComponent(jLabel4))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
              .addComponent(jtfIe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jtfRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addComponent(jtfCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jLabel8)
                  .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jtfComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jtfNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
              .addGroup(jpDadosLayout.createSequentialGroup()
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                  .addComponent(jLabel10)
                  .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                  .addComponent(jtfBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jtfIdCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jtfCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jtfCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addComponent(jLabel11)
            .addGap(31, 31, 31)))
        .addGap(7, 7, 7)
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addComponent(jLabel15)
            .addGap(6, 6, 6)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
          .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDadosLayout.createSequentialGroup()
            .addComponent(jbAddEmail)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jbEditEmail)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jbRemoveEmail))
          .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addComponent(jbAddTelefone)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jbEditTelefone)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jbRemoveTelefone)))
        .addGap(11, 11, 11))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGap(4, 4, 4)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jpDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addComponent(jScrollPane1)))
      .addComponent(JtbMaster, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(JtbMaster, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jpDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addGap(13, 13, 13))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void JbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbNovoActionPerformed
    fControl.novo();
  }//GEN-LAST:event_JbNovoActionPerformed

  private void JbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbSalvarActionPerformed
    fControl.salvar();
  }//GEN-LAST:event_JbSalvarActionPerformed

  private void JbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbEditarActionPerformed
    fControl.editar();
  }//GEN-LAST:event_JbEditarActionPerformed

  private void JbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbCancelarActionPerformed
    fControl.cancelar();
  }//GEN-LAST:event_JbCancelarActionPerformed

  private void JbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbExcluirActionPerformed
    fControl.excluir();
  }//GEN-LAST:event_JbExcluirActionPerformed

  private void JbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbBuscarActionPerformed
    fControl.pesquisar();
  }//GEN-LAST:event_JbBuscarActionPerformed

  private void JbRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbRelatorioActionPerformed
    try {
//      Master.setJpbStatusIndeterminate(true);
//      Master.setTextJlStatus("Gerando relatório...");
      ThreadReport thReport = new ThreadReport();
      thReport.start();

    } catch (Exception e) {
      Util.msgErro(e, "Erro ao gerar o relatório");
    }
  }//GEN-LAST:event_JbRelatorioActionPerformed

  private void JbRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbRefreshActionPerformed
    fControl.listar();
    jlFiltro.setVisible(false);
    JbBuscar.setEnabled(false);
  }//GEN-LAST:event_JbRefreshActionPerformed

  private void jtFornecedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtFornecedorMouseClicked
    if (fornTm.getRowCount() > 0 && (jtfId.getText() != null && jtfRazao != null)) {
      fControl.habilitaJb(true, false, true, false, true);
      fControl.habilitaJtf(false);
      fControl.limpar();
      fControl.selecionado();
    }
  }//GEN-LAST:event_jtFornecedorMouseClicked

  private void jtfIdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfIdKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfFantasia.requestFocus();
    }
  }//GEN-LAST:event_jtfIdKeyPressed

  private void jtfFantasiaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFantasiaKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfRazao.requestFocus();
    }
  }//GEN-LAST:event_jtfFantasiaKeyPressed

  private void jtfRazaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRazaoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jcbPFisica.requestFocus();
    }
  }//GEN-LAST:event_jtfRazaoKeyPressed

  private void jtfCnpjKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCnpjKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfIe.requestFocus();
    }
  }//GEN-LAST:event_jtfCnpjKeyPressed

  private void jtfIeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfIeKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfRua.requestFocus();
    }
  }//GEN-LAST:event_jtfIeKeyPressed

  private void jtfRuaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRuaKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfComplemento.requestFocus();
    }
  }//GEN-LAST:event_jtfRuaKeyPressed

  private void jtfComplementoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfComplementoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfNumero.requestFocus();
    }
  }//GEN-LAST:event_jtfComplementoKeyPressed

  private void jtfNumeroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfNumeroKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfBairro.requestFocus();
    }
  }//GEN-LAST:event_jtfNumeroKeyPressed

  private void jtfBairroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfBairroKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfIdCidade.requestFocus();
    }
  }//GEN-LAST:event_jtfBairroKeyPressed

  private void jtfIdCidadeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfIdCidadeKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      CidadeRn cidRn = new CidadeRn();
      if (jtfIdCidade.getText().isEmpty()) {
        selecionarCidade();
        Cidade cid = cidRn.carregar(Integer.parseInt(jtfIdCidade.getText()));
        jtfCidade.setText(cid.getDescricao());
      } else {
        Cidade cid = cidRn.carregar(Integer.parseInt(jtfIdCidade.getText()));
        if (cid != null) {
          jtfCidade.setText(cid.getDescricao());
          jtfCep.requestFocus();
        }
      }
    } else if (evt.getKeyCode() == KeyEvent.VK_F12) {
      selecionarCidade();
    }
  }//GEN-LAST:event_jtfIdCidadeKeyPressed

  private void jtfCidadeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCidadeKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfCep.requestFocus();
    }
  }//GEN-LAST:event_jtfCidadeKeyPressed

  private void jtfCepKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfCepKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtaObs.requestFocus();
    }
  }//GEN-LAST:event_jtfCepKeyPressed

  private void jcbPFisicaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbPFisicaKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfCnpj.requestFocus();
    }
  }//GEN-LAST:event_jcbPFisicaKeyPressed

  private void jbAddTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddTelefoneActionPerformed
    FornecedorController fc = new FornecedorController(this);
    fc.addItemTelefone();
  }//GEN-LAST:event_jbAddTelefoneActionPerformed

  private void jbAddEmailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAddEmailActionPerformed
    FornecedorController fc = new FornecedorController(this);
    fc.addItemEmail();
  }//GEN-LAST:event_jbAddEmailActionPerformed

  private void jtFornecedorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtFornecedorKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_SPACE) {
      if (JbBuscar.isEnabled()) {
        fControl.pesquisar();
      }
    } else if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      if (modoConsultaExt) {
        fControl.selecionaRegistro();
      }
    }
  }//GEN-LAST:event_jtFornecedorKeyPressed

  private void jtfFantasiaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfFantasiaKeyReleased
    Util.setFirstLetterUpperCase(jtfFantasia, jtfFantasia.getSelectionStart());
  }//GEN-LAST:event_jtfFantasiaKeyReleased

  private void jtfRazaoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRazaoKeyReleased
    Util.setFirstLetterUpperCase(jtfRazao, jtfRazao.getSelectionStart());
  }//GEN-LAST:event_jtfRazaoKeyReleased

  private void jtfRuaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfRuaKeyReleased
    Util.setFirstLetterUpperCase(jtfRua, jtfRua.getSelectionStart());
  }//GEN-LAST:event_jtfRuaKeyReleased

  private void jtfBairroKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfBairroKeyReleased
    Util.setFirstLetterUpperCase(jtfBairro, jtfBairro.getSelectionStart());
  }//GEN-LAST:event_jtfBairroKeyReleased

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException ex) {
      java.util.logging.Logger.getLogger(FornecedorJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
      java.util.logging.Logger.getLogger(FornecedorJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
      java.util.logging.Logger.getLogger(FornecedorJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(FornecedorJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        FornecedorJDialog dialog = new FornecedorJDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
        dialog.setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton JbBuscar;
  private javax.swing.JButton JbCancelar;
  private javax.swing.JButton JbEditar;
  private javax.swing.JButton JbExcluir;
  private javax.swing.JButton JbNovo;
  private javax.swing.JButton JbRefresh;
  private javax.swing.JButton JbRelatorio;
  private javax.swing.JButton JbSalvar;
  private javax.swing.JToolBar JtbMaster;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel15;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel5;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JScrollPane jScrollPane6;
  private javax.swing.JScrollPane jScrollPane7;
  private javax.swing.JToolBar.Separator jSeparator1;
  private javax.swing.JToolBar.Separator jSeparator2;
  private javax.swing.JButton jbAddEmail;
  private javax.swing.JButton jbAddTelefone;
  private javax.swing.JButton jbEditEmail;
  private javax.swing.JButton jbEditTelefone;
  private javax.swing.JButton jbRemoveEmail;
  private javax.swing.JButton jbRemoveTelefone;
  private javax.swing.JCheckBox jcbPFisica;
  private javax.swing.JLabel jlFiltro;
  private javax.swing.JPanel jpDados;
  private javax.swing.JTable jtEmail;
  private javax.swing.JTable jtFornecedor;
  private javax.swing.JTable jtTelefone;
  private javax.swing.JTextArea jtaObs;
  private javax.swing.JTextField jtfBairro;
  private javax.swing.JTextField jtfCep;
  private javax.swing.JTextField jtfCidade;
  private javax.swing.JTextField jtfCnpj;
  private javax.swing.JTextField jtfComplemento;
  private javax.swing.JTextField jtfFantasia;
  private javax.swing.JTextField jtfId;
  private javax.swing.JTextField jtfIdCidade;
  private javax.swing.JTextField jtfIe;
  private javax.swing.JTextField jtfNumero;
  private javax.swing.JTextField jtfRazao;
  private javax.swing.JTextField jtfRua;
  // End of variables declaration//GEN-END:variables
  private Util.SomenteNumeros djtfCep = new Util().new SomenteNumeros();
  private Util.SomenteNumeros djtfCnpj = new Util().new SomenteNumeros();
  private Util.SomenteNumeros djtfIdCidade = new Util().new SomenteNumeros();
  private Util.SomenteNumeros djtfIe = new Util().new SomenteNumeros();

  private void getLarguraJtBanco() {
    int grade;
    int column = fornTm.getColumnCount();
    //JtBanco.getColumnModel().getSelectedColumnCount();
    for (int i = 0; i < column; i++) {
      grade = this.jtFornecedor.getColumnModel().getColumn(i).getPreferredWidth();
      System.out.println(grade);
    }
  }

  private void getPositionColumns() {
    System.out.println(jtFornecedor.getColumnModel().getColumn(0).getHeaderValue());
  }

  private void selecionarCidade() {
    CidadeJDialog.getInstance(null, true, jtfIdCidade, jtfCidade).setVisible(true);
  }

  class ThreadReport extends Thread {

    @Override
    public void run() {
      try {
        fControl.report();
      } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
      }
    }
  }

  public FornecedorTableModel getFornTm() {
    return fornTm;
  }

  public void setFornTm(FornecedorTableModel fornTm) {
    this.fornTm = fornTm;
  }

  public List<Fornecedor> getLstForn() {
    return lstForn;
  }

  public void setLstForn(List<Fornecedor> lstForn) {
    this.lstForn = lstForn;
  }

  public JButton getJbBuscar() {
    return JbBuscar;
  }

  public void setJbBuscar(JButton JbBuscar) {
    this.JbBuscar = JbBuscar;
  }

  public JButton getJbCancelar() {
    return JbCancelar;
  }

  public void setJbCancelar(JButton JbCancelar) {
    this.JbCancelar = JbCancelar;
  }

  public JButton getJbEditar() {
    return JbEditar;
  }

  public void setJbEditar(JButton JbEditar) {
    this.JbEditar = JbEditar;
  }

  public JButton getJbExcluir() {
    return JbExcluir;
  }

  public void setJbExcluir(JButton JbExcluir) {
    this.JbExcluir = JbExcluir;
  }

  public JButton getJbNovo() {
    return JbNovo;
  }

  public void setJbNovo(JButton JbNovo) {
    this.JbNovo = JbNovo;
  }

  public JButton getJbRefresh() {
    return JbRefresh;
  }

  public void setJbRefresh(JButton JbRefresh) {
    this.JbRefresh = JbRefresh;
  }

  public JButton getJbRelatorio() {
    return JbRelatorio;
  }

  public void setJbRelatorio(JButton JbRelatorio) {
    this.JbRelatorio = JbRelatorio;
  }

  public JButton getJbSalvar() {
    return JbSalvar;
  }

  public void setJbSalvar(JButton JbSalvar) {
    this.JbSalvar = JbSalvar;
  }

  public JToolBar getJtbMaster() {
    return JtbMaster;
  }

  public void setJtbMaster(JToolBar JtbMaster) {
    this.JtbMaster = JtbMaster;
  }

  public JLabel getjLabel1() {
    return jLabel1;
  }

  public void setjLabel1(JLabel jLabel1) {
    this.jLabel1 = jLabel1;
  }

  public JLabel getjLabel10() {
    return jLabel10;
  }

  public void setjLabel10(JLabel jLabel10) {
    this.jLabel10 = jLabel10;
  }

  public JLabel getjLabel11() {
    return jLabel11;
  }

  public void setjLabel11(JLabel jLabel11) {
    this.jLabel11 = jLabel11;
  }

  public JLabel getjLabel12() {
    return jLabel12;
  }

  public void setjLabel12(JLabel jLabel12) {
    this.jLabel12 = jLabel12;
  }

  public JLabel getjLabel15() {
    return jLabel15;
  }

  public void setjLabel15(JLabel jLabel15) {
    this.jLabel15 = jLabel15;
  }

  public JLabel getjLabel2() {
    return jLabel2;
  }

  public void setjLabel2(JLabel jLabel2) {
    this.jLabel2 = jLabel2;
  }

  public JLabel getjLabel3() {
    return jLabel3;
  }

  public void setjLabel3(JLabel jLabel3) {
    this.jLabel3 = jLabel3;
  }

  public JLabel getjLabel4() {
    return jLabel4;
  }

  public void setjLabel4(JLabel jLabel4) {
    this.jLabel4 = jLabel4;
  }

  public JLabel getjLabel5() {
    return jLabel5;
  }

  public void setjLabel5(JLabel jLabel5) {
    this.jLabel5 = jLabel5;
  }

  public JLabel getjLabel7() {
    return jLabel7;
  }

  public void setjLabel7(JLabel jLabel7) {
    this.jLabel7 = jLabel7;
  }

  public JLabel getjLabel8() {
    return jLabel8;
  }

  public void setjLabel8(JLabel jLabel8) {
    this.jLabel8 = jLabel8;
  }

  public JLabel getjLabel9() {
    return jLabel9;
  }

  public void setjLabel9(JLabel jLabel9) {
    this.jLabel9 = jLabel9;
  }

  public JScrollPane getjScrollPane1() {
    return jScrollPane1;
  }

  public void setjScrollPane1(JScrollPane jScrollPane1) {
    this.jScrollPane1 = jScrollPane1;
  }

  public JScrollPane getjScrollPane2() {
    return jScrollPane2;
  }

  public void setjScrollPane2(JScrollPane jScrollPane2) {
    this.jScrollPane2 = jScrollPane2;
  }

  public JToolBar.Separator getjSeparator1() {
    return jSeparator1;
  }

  public void setjSeparator1(JToolBar.Separator jSeparator1) {
    this.jSeparator1 = jSeparator1;
  }

  public JToolBar.Separator getjSeparator2() {
    return jSeparator2;
  }

  public void setjSeparator2(JToolBar.Separator jSeparator2) {
    this.jSeparator2 = jSeparator2;
  }

  public JCheckBox getJcbPFisica() {
    return jcbPFisica;
  }

  public void setJcbPFisica(JCheckBox jcbPFisica) {
    this.jcbPFisica = jcbPFisica;
  }

  public JPanel getJpDados() {
    return jpDados;
  }

  public void setJpDados(JPanel jpDados) {
    this.jpDados = jpDados;
  }

  public JTable getJtFornecedor() {
    return jtFornecedor;
  }

  public void setJtFornecedor(JTable jtFornecedor) {
    this.jtFornecedor = jtFornecedor;
  }

  public JTextArea getJtaObs() {
    return jtaObs;
  }

  public void setJtaObs(JTextArea jtaObs) {
    this.jtaObs = jtaObs;
  }

  public JTextField getJtfBairro() {
    return jtfBairro;
  }

  public void setJtfBairro(JTextField jtfBairro) {
    this.jtfBairro = jtfBairro;
  }

  public JTextField getJtfCep() {
    return jtfCep;
  }

  public void setJtfCep(JTextField jtfCep) {
    this.jtfCep = jtfCep;
  }

  public JTextField getJtfCidade() {
    return jtfCidade;
  }

  public void setJtfCidade(JTextField jtfCidade) {
    this.jtfCidade = jtfCidade;
  }

  public JTextField getJtfCnpj() {
    return jtfCnpj;
  }

  public void setJtfCnpj(JTextField jtfCnpj) {
    this.jtfCnpj = jtfCnpj;
  }

  public JTextField getJtfComplemento() {
    return jtfComplemento;
  }

  public void setJtfComplemento(JTextField jtfComplemento) {
    this.jtfComplemento = jtfComplemento;
  }

  public JTextField getJtfFantasia() {
    return jtfFantasia;
  }

  public void setJtfFantasia(JTextField jtfFantasia) {
    this.jtfFantasia = jtfFantasia;
  }

  public JTextField getJtfId() {
    return jtfId;
  }

  public void setJtfId(JTextField jtfId) {
    this.jtfId = jtfId;
  }

  public JTextField getJtfIdCidade() {
    return jtfIdCidade;
  }

  public void setJtfIdCidade(JTextField jtfIdCidade) {
    this.jtfIdCidade = jtfIdCidade;
  }

  public JTextField getJtfIe() {
    return jtfIe;
  }

  public void setJtfIe(JTextField jtfIe) {
    this.jtfIe = jtfIe;
  }

  public JTextField getJtfNumero() {
    return jtfNumero;
  }

  public void setJtfNumero(JTextField jtfNumero) {
    this.jtfNumero = jtfNumero;
  }

  public JTextField getJtfRazao() {
    return jtfRazao;
  }

  public void setJtfRazao(JTextField jtfRazao) {
    this.jtfRazao = jtfRazao;
  }

  public JTextField getJtfRua() {
    return jtfRua;
  }

  public void setJtfRua(JTextField jtfRua) {
    this.jtfRua = jtfRua;
  }

  public TelefoneTableModel getTelTm() {
    return telTm;
  }

  public void setTelTm(TelefoneTableModel telTm) {
    this.telTm = telTm;
  }

  public EmailTableModel getEmTm() {
    return emTm;
  }

  public void setEmTm(EmailTableModel emTm) {
    this.emTm = emTm;
  }

  public JButton getJbAddEmail() {
    return jbAddEmail;
  }

  public void setJbAddEmail(JButton jbAddEmail) {
    this.jbAddEmail = jbAddEmail;
  }

  public JButton getJbAddTelefone() {
    return jbAddTelefone;
  }

  public void setJbAddTelefone(JButton jbAddTelefone) {
    this.jbAddTelefone = jbAddTelefone;
  }

  public JButton getJbRemoveEmail() {
    return jbEditEmail;
  }

  public void setJbRemoveEmail(JButton jbRemoveEmail) {
    this.jbEditEmail = jbRemoveEmail;
  }

  public JButton getJbRemoveTelefone() {
    return jbEditTelefone;
  }

  public void setJbRemoveTelefone(JButton jbRemoveTelefone) {
    this.jbEditTelefone = jbRemoveTelefone;
  }

  public JTable getJtEmail() {
    return jtEmail;
  }

  public void setJtEmail(JTable jtEmail) {
    this.jtEmail = jtEmail;
  }

  public JTable getJtTelefone() {
    return jtTelefone;
  }

  public void setJtTelefone(JTable jtTelefone) {
    this.jtTelefone = jtTelefone;
  }

  public int getIdEnd() {
    return idEnd;
  }

  public void setIdEnd(int idEnd) {
    this.idEnd = idEnd;
  }

  public JButton getJbEditEmail() {
    return jbEditEmail;
  }

  public void setJbEditEmail(JButton jbEditEmail) {
    this.jbEditEmail = jbEditEmail;
  }

  public JButton getJbEditTelefone() {
    return jbEditTelefone;
  }

  public void setJbEditTelefone(JButton jbEditTelefone) {
    this.jbEditTelefone = jbEditTelefone;
  }

  public JLabel getJlFiltro() {
    return jlFiltro;
  }

  public void setJlFiltro(JLabel jlFiltro) {
    this.jlFiltro = jlFiltro;
  }

  public JTextField getIdPesquisa() {
    return idPesquisa;
  }

  public void setIdPesquisa(JTextField idPesquisa) {
    this.idPesquisa = idPesquisa;
  }

  public JTextField getRazaoPesquisa() {
    return razaoPesquisa;
  }

  public void setRazaoPesquisa(JTextField razaoPesquisa) {
    this.razaoPesquisa = razaoPesquisa;
  }

  public boolean isModoConsultaExt() {
    return modoConsultaExt;
  }

  public void setModoConsultaExt(boolean modoConsultaExt) {
    this.modoConsultaExt = modoConsultaExt;
  }
}
